How can I create backup script for selected tables in Oracle?
How can I create backup script for selected tables in Oracle?
536
17-Jul-2023
Updated on 18-Jul-2023
Aryan Kumar
18-Jul-2023Sure, here is how you can create a backup script for selected tables in Oracle:
SQL
This script will create a backup for the tables
table1,table2, andtable3. The backup tables will be namedBAK_table1,BAK_table2, andBAK_table3.To run the script, you would save it as a text file and then execute it from SQLPlus. For example, if you saved the script as
backup_script.sql, you would run it by typing the following command into SQLPlus:SQL
This would create the backup tables for the specified tables.
Here is an explanation of the code in the script:
SET SERVEROUTPUT ONstatement tells Oracle to display output from the script.DECLAREstatement declares a variable namedv_table_nameto hold the name of the current table.FORloop iterates through the list of tables and creates a backup for each one.dbms_output.put_line()procedure displays a message to the console.EXECUTE IMMEDIATEstatement executes the specified SQL statement.ENDstatement marks the end of theFORloop.